package n1934;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class Main {

	static int a[][]=new int[81][81];
	static String s1,s2;
	static void solve(){
		for(int i=0;i<=s1.length();i++)a[i][0]=0;
		for(int i=0;i<=s2.length();i++)a[0][i]=0;
		
		for(int i=1;i<=s1.length();i++)
			for(int j=1;j<=s2.length();j++)
			{
				if(s1.charAt(i-1)==s2.charAt(j-1))
				{
					a[i][j]=a[i-1][j-1]+1;
				}else {
					a[i][j]=Math.max(a[i-1][j], a[i][j-1]);
				}
			}
		
//		for(int i=0;i<=s1.length();i++)
//		{
//			for(int j=0;j<=s2.length();j++)
//			{
//				System.out.print(a[i][j]+" ");
//			}
//			System.out.println();
//		}
	}
	
	static char[] res=new char[81];
	

	static Set<String>[][] set=new Set[81][81];
	
	
	
	static Set<String> print(int m,int n)
	{
		
		if(m<=0||n<=0||a[m][n]==0)return null;
		
//		System.out.println(m+","+n);
		
		if(set[m][n]!=null)return set[m][n];
		
		set[m][n]=new HashSet<String>();
		
		
		if(s1.charAt(m-1)==s2.charAt(n-1))
		{
			Set<String> s=print(m-1,n-1);
			if(s!=null&&s.size()>0) {
				for(String tmp:s)
				{
					set[m][n].add(tmp+s1.charAt(m-1));
				}
			}else {
				set[m][n].add(String.valueOf(s1.charAt(m-1)));
			}
			
		}
		
		if(a[m][n]==a[m-1][n])
		{
			Set<String> s=print(m-1,n);
			if(s!=null)set[m][n].addAll(s);
		}
		
		if(a[m][n]==a[m][n-1])
		{
			Set<String> s=print(m,n-1);
			if(s!=null)set[m][n].addAll(s);
		}
		
//		System.out.println(m+","+n+":"+set[m][n].size());
		return set[m][n];
	}
	
	static void output()
	{
		String tmp[]=new String[set[s1.length()][s2.length()].size()];
		set[s1.length()][s2.length()].toArray(tmp);
		Arrays.sort(tmp);
		for(int i=0;i<tmp.length;i++)System.out.println(tmp[i]);
	}
	
	
	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception {

		BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
		s1=bf.readLine();
		s2=bf.readLine();
		solve();
		print(s1.length(),s2.length());
		output();
	}

}
